//
//  SSCommentCell.m
//  starspaceVR
//
//  Created by 曹端芹 on 17/9/19.
//  Copyright © 2017年 starspace. All rights reserved.
//

#import "SSCommentCell.h"
#import "SSDetailCommentCell.h"


@interface SSCommentCell () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) NSMutableArray *commentArrM;
@end


static NSString *const detailCommentCellID = @"detailCommentCellID";
@implementation SSCommentCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
   self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}


- (void) setupUI {
    
    UIView *spare = [[UIView alloc] init];
    spare.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:spare];
    [spare mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(self.contentView);
        make.height.mas_equalTo(10);
    }];
    
    
    [self.contentView addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(spare.mas_bottom).mas_offset(10);
        make.left.right.bottom.mas_equalTo(self.contentView);
    }];
}

- (void)setDataSource:(NSArray *)dataSource {
    _dataSource = dataSource;
    [self.tableView reloadData];
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SSDetailCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:detailCommentCellID forIndexPath:indexPath];
    cell.model = self.dataSource[indexPath.row];
    return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return [tableView fd_heightForCellWithIdentifier:detailCommentCellID configuration:^(id cell) {
        [self configureCell:cell atIndexPath:indexPath];
    }];
}

- (void)configureCell:(SSDetailCommentCell *)cell atIndexPath:(NSIndexPath *)indexpath {
    cell.model = self.dataSource[indexpath.row];
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.scrollEnabled = NO;
        [_tableView registerNib:[UINib nibWithNibName:@"SSDetailCommentCell" bundle:nil] forCellReuseIdentifier:detailCommentCellID];
    }
    return _tableView;

}


- (NSMutableArray *)commentArrM {
    if (!_commentArrM) {
        _commentArrM = [NSMutableArray array];
    }
    return _commentArrM;

}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
